﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Service;
using Model;
using System.Data.SqlClient;
namespace Manager
{
    /// <summary>
    /// HW_XXX_User业务逻辑
    /// 创建人：Wilson
    /// 创建时间：2013-1-29  
    /// </summary>
    public class HW_XXX_UserManager
    {
        			
        #region##通过主键ID得到HW_XXX_User
        /// <summary>
        /// 功能：通过ID得到HW_XXX_User
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-29   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
        public HW_XXX_User GetById(string xx_username)
        {            
            using (HW_XXX_UserService ws = new HW_XXX_UserService())
			{
				return ws.GetById(xx_username);
			}
        }
        #endregion
		
		#region##通过主键ID删除HW_XXX_User
        /// <summary>
        /// 功能：通过主键ID删除HW_XXX_User
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-29   
        /// </summary>
        /// <param name="">主键ID</param>
        /// <returns></returns>
		public int DeleteById(string xx_username)
		{
			using (HW_XXX_UserService ws = new HW_XXX_UserService())
			{
				return ws.DeleteById(xx_username);
			}
		}
		#endregion			
		
        #region##添加HW_XXX_User
        /// <summary>
        /// 功能：添加HW_XXX_User
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-29
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int Add(HW_XXX_User hw_xxx_user)
        {
            using (HW_XXX_UserService ws = new HW_XXX_UserService())
			{
				return ws.Add(hw_xxx_user);
			}
        }
        #endregion
		
		#region##得到HW_XXX_User集合
		/// <summary>
        /// 功能：得到HW_XXX_User集合
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-29
        /// </summary>       
        /// <returns></returns>
		public IList<HW_XXX_User> GetList()
		{
		    using (HW_XXX_UserService ws = new HW_XXX_UserService())
			{
				return ws.GetList();
			}
		}
		#endregion
		
		#region##修改HW_XXX_User
        /// <summary>
        /// 功能：修改HW_XXX_User
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-29
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int ModHW_XXX_User(HW_XXX_User hw_xxx_user)
        {
            using (HW_XXX_UserService ws = new HW_XXX_UserService())
			{
				return ws.ModHW_XXX_User(hw_xxx_user);
			}
        }
        #endregion
		
		#region##统计HW_XXX_User
		/// <summary>
        /// 修改HW_XXX_User
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-29
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
		public int SelectCount()
		{
			using (HW_XXX_UserService ws = new HW_XXX_UserService())
			{
				return ws.SelectCount();
			}
		}
        /// <summary>
        /// 修改HW_XXX_User
        /// 创建人：  Wilson 
        /// 创建时间：2013-1-29
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public int SelectCountById()
        {
            using (HW_XXX_UserService ws = new HW_XXX_UserService())
			{
				return ws.SelectCountById();
			}
        }
		#endregion
        #region##自定义HW_XXX_User
        public HW_XXX_User CheckUser(string userName)
        {
            using (HW_XXX_UserService ws = new HW_XXX_UserService())
            {
                HW_XXX_User user = ws.CheckUser(userName);
                if (user != null)
                {
                    if ( user.RoleId > 0 && user.RoleId < 2000)
                    {
                        HW_Manger_Admin_UserManager adminManager = new HW_Manger_Admin_UserManager();
                        HW_Manger_Admin_User admin = adminManager.GetByUserName(userName);
                        user.AdminUser=admin;
                        return user;
                    }
                    if (user.RoleId == 2000)
                    {
                        HW_OrgUserManager orgUserManager=new HW_OrgUserManager ();

                        user.OrgUser = orgUserManager.GetByUserName(userName);

                    }
                    if (user.RoleId == 3000)
                    {
                        HW_School_UserManager schoolUserManager = new HW_School_UserManager();
                        user.SchoolUser=schoolUserManager.GetByUserName(userName);
                    }
                }
                return user;
            }
        }
        public void ChangePassword(string username,string password)
        {
            var user = GetById(username);
            password=SecrityPass.GetPassword(password);
            try{
                if (user.RoleId > 0 && user.RoleId < 2000)
                {
                    HW_Manger_Admin_UserManager managerws = new HW_Manger_Admin_UserManager();
                    managerws.ResetPassWord(username, password);
                }
                if (user.RoleId == 2000)
                {
                    HW_OrgManager manager = new HW_OrgManager();
                    manager.ResetPassWord(username, password);
                    
                }
                if (user.RoleId == 3000)
                {
                    HW_School_UserManager manager = new HW_School_UserManager();
                    manager.ResetPassWord(username, password);
                }
            }
            catch(Exception e)
            {
                throw e;
            }
            
        }
        #endregion
    }
}